package com.chushouya.controller.product.admin;

import com.chushouya.common.constant.ServiceType;
import com.chushouya.product.dto.admin.evaluateitem.*;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.general.framework.web.annotations.RepeatSubmit;
import com.chushouya.product.service.admin.EvaluateItemValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = ServiceType.PLATFORM + "估价项目选项管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/evaluateItemValue")
public class EvaluateItemValueController {

    @Resource
    private EvaluateItemValueService evaluateItemValueService;

    @ApiOperation("获取估价项目选项分页列表")
    @GetMapping("/page")
    public Response<PageResult<EvaluateItemValueListDTO>> page(EvaluateItemValueQuery query) {
        return Response.success(evaluateItemValueService.selectEvaluateItemValuePageResult(query));
    }

    @ApiOperation("获取估价项目选项列表")
    @GetMapping("/list")
    public Response<List<EvaluateItemValueListDTO>> list(EvaluateItemValueQuery query) {
        return Response.success(evaluateItemValueService.selectEvaluateItemValueList(query));
    }

    @ApiOperation("根据ID获取估价项目选项详细信息")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "valueId", value = "估价项目选项ID", required = true),
    })
    public Response<EvaluateItemValueDetailDTO> getDetail(Long valueId) {
        return Response.success(evaluateItemValueService.getEvaluateItemValueDetail(valueId));
    }

    @ApiOperation("新增估价项目选项")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public Response<Long> add(@Validated @RequestBody EvaluateItemValueSaveDTO evaluateItemValue) {
        return Response.success(evaluateItemValueService.addEvaluateItemValue(evaluateItemValue));
    }

    @ApiOperation("修改估价项目选项")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Response<Long> edit(@Validated @RequestBody EvaluateItemValueUpdateDTO evaluateItemValue) {
        return Response.success(evaluateItemValueService.editEvaluateItemValue(evaluateItemValue));
    }

    @ApiOperation("修改估价项目选项状态")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/editStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "valueId", value = "估价项目选项ID", required = true),
            @ApiImplicitParam(name = "status", value = "状态 0禁用 1启用", required = true)
    })
    public Response<Long> editStatus(Long valueId, Integer status) {
        return Response.success(evaluateItemValueService.editEvaluateItemValueStatus(valueId, status));
    }

    @ApiOperation("删除估价项目选项")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "valueId", value = "估价项目选项ID", required = true)
    })
    public Response<Void> remove(Long valueId) {
        evaluateItemValueService.removeEvaluateItemValue(valueId);
        return Response.success();
    }

    @ApiOperation("根据估价项目ID获取选项列表")
    @GetMapping("/listByEvaluateItemId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "evaluateItemId", value = "估价项目ID", required = true)
    })
    public Response<List<EvaluateItemValueListDTO>> listByEvaluateItemId(Long evaluateItemId) {
        return Response.success(evaluateItemValueService.selectEvaluateItemValueListByEvaluateItemId(evaluateItemId));
    }

    @ApiOperation("获取估价项目和项目选项组合信息列表")
    @GetMapping("/combineList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "分类ID", required = false)
    })
    public Response<List<EvaluateItemCombineDTO>> getCombineList(@RequestParam(required = false) Long categoryId) {
        return Response.success(evaluateItemValueService.selectEvaluateItemCombineList(categoryId));
    }
}
